home *** CD-ROM | disk | FTP | other *** search
- Date: Wed, 13 Mar 85 16:54:45 pst
- From: decvax!ucbvax!UCBJADE!ucbjade:mwm (Mike Meyer)
- Subject: XLISP 1.4 part 2 (of 4)
-
-
- #! /bin/sh
- # This is a shell archive, meaning:
- # 1. Remove everything above the #! /bin/sh line.
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh (not csh) to create the files:
- # xlbfun.c
- # xlcont.c
- # xllist.c
- # xlobj.c
- # This archive created: Mon Dec 2 10:13:10 1985
- export PATH; PATH=/bin:$PATH
- echo shar: extracting "'xlbfun.c'" '(8689 characters)'
- if test -f 'xlbfun.c'
- then
- echo shar: will not over-write existing file "'xlbfun.c'"
- else
- sed 's/^X//' << \SHAR_EOF > 'xlbfun.c'
- /* xlbfun.c - xlisp basic builtin functions */
-
- #include "xlisp.h"
-
- /* external variables */
- extern NODE *xlstack;
- extern NODE *s_lambda,*s_macro;
- extern NODE *s_comma,*s_comat;
- extern NODE *s_unbound;
- extern char gsprefix[];
- extern int gsnumber;
-
- /* forward declarations */
- XFORWARD NODE *bquote1();
- XFORWARD NODE *defun();
- XFORWARD NODE *makesymbol();
-
- /* xeval - the builtin function 'eval' */
- NODE *xeval(args)
- NODE *args;
- {
- NODE *oldstk,expr,*val;
-
- /* create a new stack frame */
- oldstk = xlsave(&expr,NULL);
-
- /* get the expression to evaluate */
- expr.n_ptr = xlarg(&args);
- xllastarg(args);
-
- /* evaluate the expression */
- val = xleval(expr.n_ptr);
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the expression evaluated */
- return (val);
- }
-
- /* xapply - the builtin function 'apply' */
- NODE *xapply(args)
- NODE *args;
- {
- NODE *oldstk,fun,arglist,*val;
-
- /* create a new stack frame */
- oldstk = xlsave(&fun,&arglist,NULL);
-
- /* get the function and argument list */
- fun.n_ptr = xlarg(&args);
- arglist.n_ptr = xlarg(&args);
- xllastarg(args);
-
- /* if the function is a symbol, get its value */
- if (symbolp(fun.n_ptr))
- fun.n_ptr = xleval(fun.n_ptr);
-
- /* apply the function to the arguments */
- val = xlapply(fun.n_ptr,arglist.n_ptr);
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the expression evaluated */
- return (val);
- }
-
- /* xfuncall - the builtin function 'funcall' */
- NODE *xfuncall(args)
- NODE *args;
- {
- NODE *oldstk,fun,arglist,*val;
-
- /* create a new stack frame */
- oldstk = xlsave(&fun,&arglist,NULL);
-
- /* get the function and argument list */
- fun.n_ptr = xlarg(&args);
- arglist.n_ptr = args;
-
- /* if the function is a symbol, get its value */
- if (symbolp(fun.n_ptr))
- fun.n_ptr = xleval(fun.n_ptr);
-
- /* apply the function to the arguments */
- val = xlapply(fun.n_ptr,arglist.n_ptr);
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the expression evaluated */
- return (val);
- }
-
- /* xquote - builtin function to quote an expression */
- NODE *xquote(args)
- NODE *args;
- {
- NODE *arg;
-
- /* get the argument */
- arg = xlarg(&args);
- xllastarg(args);
-
- /* return the quoted expression */
- return (arg);
- }
-
- /* xbquote - back quote function */
- NODE *xbquote(args)
- NODE *args;
- {
- NODE *oldstk,expr,*val;
-
- /* create a new stack frame */
- oldstk = xlsave(&expr,NULL);
-
- /* get the expression */
- expr.n_ptr = xlarg(&args);
- xllastarg(args);
-
- /* fill in the template */
- val = bquote1(expr.n_ptr);
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the result */
- return (val);
- }
-
- /* bquote1 - back quote helper function */
- LOCAL NODE *bquote1(expr)
- NODE *expr;
- {
- NODE *oldstk,val,list,*last,*new;
-
- /* handle atoms */
- if (atom(expr))
- val.n_ptr = expr;
-
- /* handle (comma <expr>) */
- else if (car(expr) == s_comma) {
- if (atom(cdr(expr)))
- xlfail("bad comma expression");
- val.n_ptr = xleval(car(cdr(expr)));
- }
-
- /* handle ((comma-at <expr>) ... ) */
- else if (consp(car(expr)) && car(car(expr)) == s_comat) {
- oldstk = xlsave(&list,&val,NULL);
- if (atom(cdr(car(expr))))
- xlfail("bad comma-at expression");
- list.n_ptr = xleval(car(cdr(car(expr))));
- for (last = NIL; consp(list.n_ptr); list.n_ptr = cdr(list.n_ptr)) {
- new = newnode(LIST);
- rplaca(new,car(list.n_ptr));
- if (last)
- rplacd(last,new);
- else
- val.n_ptr = new;
- last = new;
- }
- if (last)
- rplacd(last,bquote1(cdr(expr)));
- else
- val.n_ptr = bquote1(cdr(expr));
- xlstack = oldstk;
- }
-
- /* handle any other list */
- else {
- oldstk = xlsave(&val,NULL);
- val.n_ptr = newnode(LIST);
- rplaca(val.n_ptr,bquote1(car(expr)));
- rplacd(val.n_ptr,bquote1(cdr(expr)));
- xlstack = oldstk;
- }
-
- /* return the result */
- return (val.n_ptr);
- }
-
- /* xset - builtin function set */
- NODE *xset(args)
- NODE *args;
- {
- NODE *sym,*val;
-
- /* get the symbol and new value */
- sym = xlmatch(SYM,&args);
- val = xlarg(&args);
- xllastarg(args);
-
- /* assign the symbol the value of argument 2 and the return value */
- assign(sym,val);
-
- /* return the result value */
- return (val);
- }
-
- /* xsetq - builtin function setq */
- NODE *xsetq(args)
- NODE *args;
- {
- NODE *oldstk,arg,sym,val;
-
- /* create a new stack frame */
- oldstk = xlsave(&arg,&sym,&val,NULL);
-
- /* initialize */
- arg.n_ptr = args;
-
- /* handle each pair of arguments */
- while (arg.n_ptr) {
- sym.n_ptr = xlmatch(SYM,&arg.n_ptr);
- val.n_ptr = xlevarg(&arg.n_ptr);
- assign(sym.n_ptr,val.n_ptr);
- }
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the result value */
- return (val.n_ptr);
- }
-
- /* xdefun - builtin function 'defun' */
- NODE *xdefun(args)
- NODE *args;
- {
- return (defun(args,s_lambda));
- }
-
- /* xdefmacro - builtin function 'defmacro' */
- NODE *xdefmacro(args)
- NODE *args;
- {
- return (defun(args,s_macro));
- }
-
- /* defun - internal function definition routine */
- LOCAL NODE *defun(args,type)
- NODE *args,*type;
- {
- NODE *oldstk,sym,fargs,fun;
-
- /* create a new stack frame */
- oldstk = xlsave(&sym,&fargs,&fun,NULL);
-
- /* get the function symbol and formal argument list */
- sym.n_ptr = xlmatch(SYM,&args);
- fargs.n_ptr = xlmatch(LIST,&args);
-
- /* create a new function definition */
- fun.n_ptr = newnode(LIST);
- rplaca(fun.n_ptr,type);
- rplacd(fun.n_ptr,newnode(LIST));
- rplaca(cdr(fun.n_ptr),fargs.n_ptr);
- rplacd(cdr(fun.n_ptr),args);
-
- /* make the symbol point to a new function definition */
- assign(sym.n_ptr,fun.n_ptr);
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the function symbol */
- return (sym.n_ptr);
- }
-
- /* xgensym - generate a symbol */
- NODE *xgensym(args)
- NODE *args;
- {
- char sym[STRMAX+1];
- NODE *x;
-
- /* get the prefix or number */
- if (args) {
- x = xlarg(&args);
- switch (ntype(x)) {
- case STR:
- strcpy(gsprefix,x->n_str);
- break;
- case INT:
- gsnumber = x->n_int;
- break;
- default:
- xlfail("bad argument type");
- }
- }
- xllastarg(args);
-
- /* create the pname of the new symbol */
- sprintf(sym,"%s%d",gsprefix,gsnumber++);
-
- /* make a symbol with this print name */
- return (xlmakesym(sym,DYNAMIC));
- }
-
- /* xmakesymbol - make a new uninterned symbol */
- NODE *xmakesymbol(args)
- NODE *args;
- {
- return (makesymbol(args,FALSE));
- }
-
- /* xintern - make a new interned symbol */
- NODE *xintern(args)
- NODE *args;
- {
- return (makesymbol(args,TRUE));
- }
-
- /* makesymbol - make a new symbol */
- LOCAL NODE *makesymbol(args,iflag)
- NODE *args; int iflag;
- {
- NODE *oldstk,pname,*val;
- char *str;
-
- /* create a new stack frame */
- oldstk = xlsave(&pname,NULL);
-
- /* get the print name of the symbol to intern */
- pname.n_ptr = xlmatch(STR,&args);
- xllastarg(args);
-
- /* make the symbol */
- str = pname.n_ptr->n_str;
- val = (iflag ? xlenter(str,DYNAMIC) : xlmakesym(str,DYNAMIC));
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the symbol */
- return (val);
- }
-
- /* xsymname - get the print name of a symbol */
- NODE *xsymname(args)
- NODE *args;
- {
- NODE *sym;
-
- /* get the symbol */
- sym = xlmatch(SYM,&args);
- xllastarg(args);
-
- /* return the print name */
- return (car(sym->n_symplist));
- }
-
- /* xsymvalue - get the print value of a symbol */
- NODE *xsymvalue(args)
- NODE *args;
- {
- NODE *sym;
-
- /* get the symbol */
- sym = xlmatch(SYM,&args);
- xllastarg(args);
-
- /* check for an unbound symbol */
- while (sym->n_symvalue == s_unbound)
- xlunbound(sym);
-
- /* return the value */
- return (sym->n_symvalue);
- }
-
- /* xsymplist - get the property list of a symbol */
- NODE *xsymplist(args)
- NODE *args;
- {
- NODE *sym;
-
- /* get the symbol */
- sym = xlmatch(SYM,&args);
- xllastarg(args);
-
- /* return the property list */
- return (cdr(sym->n_symplist));
- }
-
- /* xget - get the value of a property */
- NODE *xget(args)
- NODE *args;
- {
- NODE *sym,*prp;
-
- /* get the symbol and property */
- sym = xlmatch(SYM,&args);
- prp = xlmatch(SYM,&args);
- xllastarg(args);
-
- /* retrieve the property value */
- return (xlgetprop(sym,prp));
- }
-
- /* xremprop - remove a property value from a property list */
- NODE *xremprop(args)
- NODE *args;
- {
- NODE *sym,*prp;
-
- /* get the symbol and property */
- sym = xlmatch(SYM,&args);
- prp = xlmatch(SYM,&args);
- xllastarg(args);
-
- /* remove the property */
- xlremprop(sym,prp);
-
- /* return nil */
- return (NIL);
- }
- SHAR_EOF
- if test 8689 -ne "`wc -c < 'xlbfun.c'`"
- then
- echo shar: error transmitting "'xlbfun.c'" '(should have been 8689 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'xlcont.c'" '(16880 characters)'
- if test -f 'xlcont.c'
- then
- echo shar: will not over-write existing file "'xlcont.c'"
- else
- sed 's/^X//' << \SHAR_EOF > 'xlcont.c'
- /* xlcont - xlisp control built-in functions */
-
- #include "xlisp.h"
-
- /* external variables */
- extern NODE *xlstack,*xlenv,*xlnewenv,*xlvalue;
- extern NODE *s_unbound;
- extern NODE *s_evalhook,*s_applyhook;
- extern NODE *true;
-
- /* external routines */
- extern NODE *xlxeval();
-
- /* forward declarations */
- XFORWARD NODE *let();
- XFORWARD NODE *prog();
- XFORWARD NODE *progx();
- XFORWARD NODE *doloop();
-
- /* xcond - built-in function 'cond' */
- NODE *xcond(args)
- NODE *args;
- {
- NODE *oldstk,arg,list,*val;
-
- /* create a new stack frame */
- oldstk = xlsave(&arg,&list,NULL);
-
- /* initialize */
- arg.n_ptr = args;
-
- /* initialize the return value */
- val = NIL;
-
- /* find a predicate that is true */
- while (arg.n_ptr) {
-
- /* get the next conditional */
- list.n_ptr = xlmatch(LIST,&arg.n_ptr);
-
- /* evaluate the predicate part */
- if (xlevarg(&list.n_ptr)) {
-
- /* evaluate each expression */
- while (list.n_ptr)
- val = xlevarg(&list.n_ptr);
-
- /* exit the loop */
- break;
- }
- }
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the value */
- return (val);
- }
-
- /* xand - built-in function 'and' */
- NODE *xand(args)
- NODE *args;
- {
- NODE *oldstk,arg,*val;
-
- /* create a new stack frame */
- oldstk = xlsave(&arg,NULL);
-
- /* initialize */
- arg.n_ptr = args;
- val = true;
-
- /* evaluate each argument */
- while (arg.n_ptr)
-
- /* get the next argument */
- if ((val = xlevarg(&arg.n_ptr)) == NIL)
- break;
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the result value */
- return (val);
- }
-
- /* xor - built-in function 'or' */
- NODE *xor(args)
- NODE *args;
- {
- NODE *oldstk,arg,*val;
-
- /* create a new stack frame */
- oldstk = xlsave(&arg,NULL);
-
- /* initialize */
- arg.n_ptr = args;
- val = NIL;
-
- /* evaluate each argument */
- while (arg.n_ptr)
- if ((val = xlevarg(&arg.n_ptr)))
- break;
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the result value */
- return (val);
- }
-
- /* xif - built-in function 'if' */
- NODE *xif(args)
- NODE *args;
- {
- NODE *oldstk,testexpr,thenexpr,elseexpr,*val;
-
- /* create a new stack frame */
- oldstk = xlsave(&testexpr,&thenexpr,&elseexpr,NULL);
-
- /* get the test expression, then clause and else clause */
- testexpr.n_ptr = xlarg(&args);
- thenexpr.n_ptr = xlarg(&args);
- elseexpr.n_ptr = (args ? xlarg(&args) : NIL);
- xllastarg(args);
-
- /* evaluate the appropriate clause */
- val = xleval(xleval(testexpr.n_ptr) ? thenexpr.n_ptr : elseexpr.n_ptr);
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the last value */
- return (val);
- }
-
- /* xlet - built-in function 'let' */
- NODE *xlet(args)
- NODE *args;
- {
- return (let(args,TRUE));
- }
-
- /* xletstar - built-in function 'let*' */
- NODE *xletstar(args)
- NODE *args;
- {
- return (let(args,FALSE));
- }
-
- /* let - common let routine */
- LOCAL NODE *let(args,pflag)
- NODE *args; int pflag;
- {
- NODE *oldstk,*oldenv,*oldnewenv,arg,*val;
-
- /* create a new stack frame */
- oldstk = xlsave(&arg,NULL);
-
- /* initialize */
- arg.n_ptr = args;
-
- /* get the list of bindings and bind the symbols */
- oldnewenv = xlnewenv; oldenv = xlnewenv = xlenv;
- dobindings(xlmatch(LIST,&arg.n_ptr),pflag);
-
- /* execute the code */
- for (val = NIL; arg.n_ptr; )
- val = xlevarg(&arg.n_ptr);
-
- /* unbind the arguments */
- xlunbind(oldenv); xlnewenv = oldnewenv;
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the result */
- return (val);
- }
-
- /* xprog - built-in function 'prog' */
- NODE *xprog(args)
- NODE *args;
- {
- return (prog(args,TRUE));
- }
-
- /* xprogstar - built-in function 'prog*' */
- NODE *xprogstar(args)
- NODE *args;
- {
- return (prog(args,FALSE));
- }
-
- /* prog - common prog routine */
- LOCAL NODE *prog(args,pflag)
- NODE *args; int pflag;
- {
- NODE *oldstk,*oldenv,*oldnewenv,arg,*val;
-
- /* create a new stack frame */
- oldstk = xlsave(&arg,NULL);
-
- /* initialize */
- arg.n_ptr = args;
-
- /* get the list of bindings and bind the symbols */
- oldnewenv = xlnewenv; oldenv = xlnewenv = xlenv;
- dobindings(xlmatch(LIST,&arg.n_ptr),pflag);
-
- /* execute the code */
- tagblock(arg.n_ptr,&val);
-
- /* unbind the arguments */
- xlunbind(oldenv); xlnewenv = oldnewenv;
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the result */
- return (val);
- }
-
- /* xgo - built-in function 'go' */
- NODE *xgo(args)
- NODE *args;
- {
- NODE *label;
-
- /* get the target label */
- label = xlarg(&args);
- xllastarg(args);
-
- /* transfer to the label */
- xlgo(label);
- }
-
- /* xreturn - built-in function 'return' */
- NODE *xreturn(args)
- NODE *args;
- {
- NODE *val;
-
- /* get the return value */
- val = (args ? xlarg(&args) : NIL);
- xllastarg(args);
-
- /* return from the inner most block */
- xlreturn(val);
- }
-
- /* xprog1 - built-in function 'prog1' */
- NODE *xprog1(args)
- NODE *args;
- {
- return (progx(args,1));
- }
-
- /* xprog2 - built-in function 'prog2' */
- NODE *xprog2(args)
- NODE *args;
- {
- return (progx(args,2));
- }
-
- /* progx - common progx code */
- LOCAL NODE *progx(args,n)
- NODE *args; int n;
- {
- NODE *oldstk,arg,val;
-
- /* create a new stack frame */
- oldstk = xlsave(&arg,&val,NULL);
-
- /* initialize */
- arg.n_ptr = args;
-
- /* evaluate the first n expressions */
- while (n--)
- val.n_ptr = xlevarg(&arg.n_ptr);
-
- /* evaluate each remaining argument */
- while (arg.n_ptr)
- xlevarg(&arg.n_ptr);
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the last test expression value */
- return (val.n_ptr);
- }
-
- /* xprogn - built-in function 'progn' */
- NODE *xprogn(args)
- NODE *args;
- {
- NODE *oldstk,arg,*val;
-
- /* create a new stack frame */
- oldstk = xlsave(&arg,NULL);
-
- /* initialize */
- arg.n_ptr = args;
-
- /* evaluate each remaining argument */
- for (val = NIL; arg.n_ptr; )
- val = xlevarg(&arg.n_ptr);
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the last test expression value */
- return (val);
- }
-
- /* xdo - built-in function 'do' */
- NODE *xdo(args)
- NODE *args;
- {
- return (doloop(args,TRUE));
- }
-
- /* xdostar - built-in function 'do*' */
- NODE *xdostar(args)
- NODE *args;
- {
- return (doloop(args,FALSE));
- }
-
- /* doloop - common do routine */
- LOCAL NODE *doloop(args,pflag)
- NODE *args; int pflag;
- {
- NODE *oldstk,*oldenv,*oldnewenv,arg,blist,clist,test,*rval;
- int rbreak;
-
- /* create a new stack frame */
- oldstk = xlsave(&arg,&blist,&clist,&test,NULL);
-
- /* initialize */
- arg.n_ptr = args;
-
- /* get the list of bindings and bind the symbols */
- blist.n_ptr = xlmatch(LIST,&arg.n_ptr);
- oldnewenv = xlnewenv; oldenv = xlnewenv = xlenv;
- dobindings(blist.n_ptr,pflag);
-
- /* get the exit test and result forms */
- clist.n_ptr = xlmatch(LIST,&arg.n_ptr);
- test.n_ptr = xlarg(&clist.n_ptr);
-
- /* execute the loop as long as the test is false */
- rbreak = FALSE;
- while (xleval(test.n_ptr) == NIL) {
-
- /* execute the body of the loop */
- if (tagblock(arg.n_ptr,&rval)) {
- rbreak = TRUE;
- break;
- }
-
- /* update the looping variables */
- doupdates(blist.n_ptr,pflag);
- }
-
- /* evaluate the result expression */
- if (!rbreak)
- for (rval = NIL; consp(clist.n_ptr); )
- rval = xlevarg(&clist.n_ptr);
-
- /* unbind the arguments */
- xlunbind(oldenv); xlnewenv = oldnewenv;
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the result */
- return (rval);
- }
-
- /* xdolist - built-in function 'dolist' */
- NODE *xdolist(args)
- NODE *args;
- {
- NODE *oldstk,*oldenv,arg,clist,sym,list,val,*rval;
- int rbreak;
-
- /* create a new stack frame */
- oldstk = xlsave(&arg,&clist,&sym,&list,&val,NULL);
-
- /* initialize */
- arg.n_ptr = args;
-
- /* get the control list (sym list result-expr) */
- clist.n_ptr = xlmatch(LIST,&arg.n_ptr);
- sym.n_ptr = xlmatch(SYM,&clist.n_ptr);
- list.n_ptr = xlevmatch(LIST,&clist.n_ptr);
- val.n_ptr = (clist.n_ptr ? xlarg(&clist.n_ptr) : NIL);
-
- /* initialize the local environment */
- oldenv = xlenv;
- xlsbind(sym.n_ptr,NIL);
-
- /* loop through the list */
- rbreak = FALSE;
- for (; consp(list.n_ptr); list.n_ptr = cdr(list.n_ptr)) {
-
- /* bind the symbol to the next list element */
- sym.n_ptr->n_symvalue = car(list.n_ptr);
-
- /* execute the loop body */
- if (tagblock(arg.n_ptr,&rval)) {
- rbreak = TRUE;
- break;
- }
- }
-
- /* evaluate the result expression */
- if (!rbreak) {
- sym.n_ptr->n_symvalue = NIL;
- rval = xleval(val.n_ptr);
- }
-
- /* unbind the arguments */
- xlunbind(oldenv);
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the result */
- return (rval);
- }
-
- /* xdotimes - built-in function 'dotimes' */
- NODE *xdotimes(args)
- NODE *args;
- {
- NODE *oldstk,*oldenv,arg,clist,sym,val,*rval;
- int rbreak,cnt,i;
-
- /* create a new stack frame */
- oldstk = xlsave(&arg,&clist,&sym,&val,NULL);
-
- /* initialize */
- arg.n_ptr = args;
-
- /* get the control list (sym list result-expr) */
- clist.n_ptr = xlmatch(LIST,&arg.n_ptr);
- sym.n_ptr = xlmatch(SYM,&clist.n_ptr);
- cnt = xlevmatch(INT,&clist.n_ptr)->n_int;
- val.n_ptr = (clist.n_ptr ? xlarg(&clist.n_ptr) : NIL);
-
- /* initialize the local environment */
- oldenv = xlenv;
- xlsbind(sym.n_ptr,NIL);
-
- /* loop through for each value from zero to cnt-1 */
- rbreak = FALSE;
- for (i = 0; i < cnt; i++) {
-
- /* bind the symbol to the next list element */
- sym.n_ptr->n_symvalue = newnode(INT);
- sym.n_ptr->n_symvalue->n_int = i;
-
- /* execute the loop body */
- if (tagblock(arg.n_ptr,&rval)) {
- rbreak = TRUE;
- break;
- }
- }
-
- /* evaluate the result expression */
- if (!rbreak) {
- sym.n_ptr->n_symvalue = newnode(INT);
- sym.n_ptr->n_symvalue->n_int = cnt;
- rval = xleval(val.n_ptr);
- }
-
- /* unbind the arguments */
- xlunbind(oldenv);
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the result */
- return (rval);
- }
-
- /* xcatch - built-in function 'catch' */
- NODE *xcatch(args)
- NODE *args;
- {
- NODE *oldstk,tag,arg,*val;
- CONTEXT cntxt;
-
- /* create a new stack frame */
- oldstk = xlsave(&tag,&arg,NULL);
-
- /* initialize */
- tag.n_ptr = xlevarg(&args);
- arg.n_ptr = args;
- val = NIL;
-
- /* establish an execution context */
- xlbegin(&cntxt,CF_THROW,tag.n_ptr);
-
- /* check for 'throw' */
- if (setjmp(cntxt.c_jmpbuf))
- val = xlvalue;
-
- /* otherwise, evaluate the remainder of the arguments */
- else {
- while (arg.n_ptr)
- val = xlevarg(&arg.n_ptr);
- }
- xlend(&cntxt);
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the result */
- return (val);
- }
-
- /* xthrow - built-in function 'throw' */
- NODE *xthrow(args)
- NODE *args;
- {
- NODE *tag,*val;
-
- /* get the tag and value */
- tag = xlarg(&args);
- val = (args ? xlarg(&args) : NIL);
- xllastarg(args);
-
- /* throw the tag */
- xlthrow(tag,val);
- }
-
- /* xerror - built-in function 'error' */
- NODE *xerror(args)
- NODE *args;
- {
- char *emsg; NODE *arg;
-
- /* get the error message and the argument */
- emsg = xlmatch(STR,&args)->n_str;
- arg = (args ? xlarg(&args) : s_unbound);
- xllastarg(args);
-
- /* signal the error */
- xlerror(emsg,arg);
- }
-
- /* xcerror - built-in function 'cerror' */
- NODE *xcerror(args)
- NODE *args;
- {
- char *cmsg,*emsg; NODE *arg;
-
- /* get the correction message, the error message, and the argument */
- cmsg = xlmatch(STR,&args)->n_str;
- emsg = xlmatch(STR,&args)->n_str;
- arg = (args ? xlarg(&args) : s_unbound);
- xllastarg(args);
-
- /* signal the error */
- xlcerror(cmsg,emsg,arg);
-
- /* return nil */
- return (NIL);
- }
-
- /* xbreak - built-in function 'break' */
- NODE *xbreak(args)
- NODE *args;
- {
- char *emsg; NODE *arg;
-
- /* get the error message */
- emsg = (args ? xlmatch(STR,&args)->n_str : "**BREAK**");
- arg = (args ? xlarg(&args) : s_unbound);
- xllastarg(args);
-
- /* enter the break loop */
- xlbreak(emsg,arg);
-
- /* return nil */
- return (NIL);
- }
-
- /* xerrset - built-in function 'errset' */
- NODE *xerrset(args)
- NODE *args;
- {
- NODE *oldstk,expr,flag,*val;
- CONTEXT cntxt;
-
- /* create a new stack frame */
- oldstk = xlsave(&expr,&flag,NULL);
-
- /* get the expression and the print flag */
- expr.n_ptr = xlarg(&args);
- flag.n_ptr = (args ? xlarg(&args) : true);
- xllastarg(args);
-
- /* establish an execution context */
- xlbegin(&cntxt,CF_ERROR,flag.n_ptr);
-
- /* check for error */
- if (setjmp(cntxt.c_jmpbuf))
- val = NIL;
-
- /* otherwise, evaluate the expression */
- else {
- expr.n_ptr = xleval(expr.n_ptr);
- val = newnode(LIST);
- rplaca(val,expr.n_ptr);
- }
- xlend(&cntxt);
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the result */
- return (val);
- }
-
- /* xevalhook - eval hook function */
- NODE *xevalhook(args)
- NODE *args;
- {
- NODE *oldstk,*oldenv,expr,ehook,ahook,*val;
-
- /* create a new stack frame */
- oldstk = xlsave(&expr,&ehook,&ahook,NULL);
-
- /* get the expression and the hook functions */
- expr.n_ptr = xlarg(&args);
- ehook.n_ptr = xlarg(&args);
- ahook.n_ptr = xlarg(&args);
- xllastarg(args);
-
- /* bind *evalhook* and *applyhook* to the hook functions */
- oldenv = xlenv;
- xlsbind(s_evalhook,ehook.n_ptr);
- xlsbind(s_applyhook,ahook.n_ptr);
-
- /* evaluate the expression (bypassing *evalhook*) */
- val = xlxeval(expr.n_ptr);
-
- /* unbind the hook variables */
- xlunbind(oldenv);
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the result */
- return (val);
- }
-
- /* dobindings - handle bindings for let/let*, prog/prog*, do/do* */
- LOCAL dobindings(blist,pflag)
- NODE *blist; int pflag;
- {
- NODE *oldstk,list,bnd,sym,val;
-
- /* create a new stack frame */
- oldstk = xlsave(&list,&bnd,&sym,&val,NULL);
-
- /* bind each symbol in the list of bindings */
- for (list.n_ptr = blist; consp(list.n_ptr); list.n_ptr = cdr(list.n_ptr)) {
-
- /* get the next binding */
- bnd.n_ptr = car(list.n_ptr);
-
- /* handle a symbol */
- if (symbolp(bnd.n_ptr)) {
- sym.n_ptr = bnd.n_ptr;
- val.n_ptr = NIL;
- }
-
- /* handle a list of the form (symbol expr) */
- else if (consp(bnd.n_ptr)) {
- sym.n_ptr = xlmatch(SYM,&bnd.n_ptr);
- val.n_ptr = xlevarg(&bnd.n_ptr);
- }
- else
- xlfail("bad binding");
-
- /* bind the value to the symbol */
- if (pflag)
- xlbind(sym.n_ptr,val.n_ptr);
- else
- xlsbind(sym.n_ptr,val.n_ptr);
- }
-
- /* fix the bindings on a parallel let */
- if (pflag)
- xlfixbindings();
-
- /* restore the previous stack frame */
- xlstack = oldstk;
- }
-
- /* doupdates - handle updates for do/do* */
- doupdates(blist,pflag)
- NODE *blist; int pflag;
- {
- NODE *oldstk,*oldenv,*oldnewenv,list,bnd,sym,val;
-
- /* create a new stack frame */
- oldstk = xlsave(&list,&bnd,&sym,&val,NULL);
-
- /* initialize the local environment */
- if (pflag) {
- oldenv = xlenv; oldnewenv = xlnewenv;
- }
-
- /* bind each symbol in the list of bindings */
- for (list.n_ptr = blist; consp(list.n_ptr); list.n_ptr = cdr(list.n_ptr)) {
-
- /* get the next binding */
- bnd.n_ptr = car(list.n_ptr);
-
- /* handle a list of the form (symbol expr) */
- if (consp(bnd.n_ptr)) {
- sym.n_ptr = xlmatch(SYM,&bnd.n_ptr);
- bnd.n_ptr = cdr(bnd.n_ptr);
- if (bnd.n_ptr) {
- val.n_ptr = xlevarg(&bnd.n_ptr);
- if (pflag)
- xlbind(sym.n_ptr,val.n_ptr);
- else
- sym.n_ptr->n_symvalue = val.n_ptr;
- }
- }
- }
-
- /* fix the bindings on a parallel let */
- if (pflag) {
- xlfixbindings();
- xlenv = oldenv; xlnewenv = oldnewenv;
- }
-
- /* restore the previous stack frame */
- xlstack = oldstk;
- }
-
- /* tagblock - execute code within a block and tagbody */
- int tagblock(code,pval)
- NODE *code,**pval;
- {
- NODE *oldstk,arg;
- CONTEXT cntxt;
- int type,sts;
-
- /* create a new stack frame */
- oldstk = xlsave(&arg,NULL);
-
- /* initialize */
- arg.n_ptr = code;
-
- /* establish an execution context */
- xlbegin(&cntxt,CF_GO|CF_RETURN,arg.n_ptr);
-
- /* check for a 'return' */
- if ((type = setjmp(cntxt.c_jmpbuf)) == CF_RETURN) {
- *pval = xlvalue;
- sts = TRUE;
- }
-
- /* otherwise, enter the body */
- else {
-
- /* check for a 'go' */
- if (type == CF_GO)
- arg.n_ptr = xlvalue;
-
- /* evaluate each expression in the body */
- while (consp(arg.n_ptr))
- if (consp(car(arg.n_ptr)))
- xlevarg(&arg.n_ptr);
- else
- arg.n_ptr = cdr(arg.n_ptr);
-
- /* indicate that we fell through the bottom of the tagbody */
- *pval = NIL;
- sts = FALSE;
- }
- xlend(&cntxt);
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return status */
- return (sts);
- }
- SHAR_EOF
- if test 16880 -ne "`wc -c < 'xlcont.c'`"
- then
- echo shar: error transmitting "'xlcont.c'" '(should have been 16880 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'xllist.c'" '(17752 characters)'
- if test -f 'xllist.c'
- then
- echo shar: will not over-write existing file "'xllist.c'"
- else
- sed 's/^X//' << \SHAR_EOF > 'xllist.c'
- /* xllist - xlisp built-in list functions */
-
- #include "xlisp.h"
-
- #ifdef MEGAMAX
- overlay "overflow"
- #endif
-
- /* external variables */
- extern NODE *xlstack;
- extern NODE *s_unbound;
- extern NODE *true;
-
- /* external routines */
- extern int eq(),eql(),equal();
-
- /* forward declarations */
- XFORWARD NODE *cxr();
- XFORWARD NODE *nth(),*assoc();
- XFORWARD NODE *subst(),*sublis(),*map();
- XFORWARD NODE *cequal();
-
- /* xcar - return the car of a list */
- NODE *xcar(args)
- NODE *args;
- {
- return (cxr(args,"a"));
- }
-
- /* xcdr - return the cdr of a list */
- NODE *xcdr(args)
- NODE *args;
- {
- return (cxr(args,"d"));
- }
-
- /* xcaar - return the caar of a list */
- NODE *xcaar(args)
- NODE *args;
- {
- return (cxr(args,"aa"));
- }
-
- /* xcadr - return the cadr of a list */
- NODE *xcadr(args)
- NODE *args;
- {
- return (cxr(args,"da"));
- }
-
- /* xcdar - return the cdar of a list */
- NODE *xcdar(args)
- NODE *args;
- {
- return (cxr(args,"ad"));
- }
-
- /* xcddr - return the cddr of a list */
- NODE *xcddr(args)
- NODE *args;
- {
- return (cxr(args,"dd"));
- }
-
- /* cxr - common car/cdr routine */
- LOCAL NODE *cxr(args,adstr)
- NODE *args; char *adstr;
- {
- NODE *list;
-
- /* get the list */
- list = xlmatch(LIST,&args);
- xllastarg(args);
-
- /* perform the car/cdr operations */
- while (*adstr && consp(list))
- list = (*adstr++ == 'a' ? car(list) : cdr(list));
-
- /* make sure the operation succeeded */
- if (*adstr && list)
- xlfail("bad argument");
-
- /* return the result */
- return (list);
- }
-
- /* xcons - construct a new list cell */
- NODE *xcons(args)
- NODE *args;
- {
- NODE *arg1,*arg2,*val;
-
- /* get the two arguments */
- arg1 = xlarg(&args);
- arg2 = xlarg(&args);
- xllastarg(args);
-
- /* construct a new list element */
- val = newnode(LIST);
- rplaca(val,arg1);
- rplacd(val,arg2);
-
- /* return the list */
- return (val);
- }
-
- /* xlist - built a list of the arguments */
- NODE *xlist(args)
- NODE *args;
- {
- NODE *oldstk,arg,list,val,*last,*lptr;
-
- /* create a new stack frame */
- oldstk = xlsave(&arg,&list,&val,NULL);
-
- /* initialize */
- arg.n_ptr = args;
-
- /* evaluate and append each argument */
- for (last = NIL; arg.n_ptr != NIL; last = lptr) {
-
- /* evaluate the next argument */
- val.n_ptr = xlarg(&arg.n_ptr);
-
- /* append this argument to the end of the list */
- lptr = newnode(LIST);
- if (last == NIL)
- list.n_ptr = lptr;
- else
- rplacd(last,lptr);
- rplaca(lptr,val.n_ptr);
- }
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the list */
- return (list.n_ptr);
- }
-
- /* xappend - built-in function append */
- NODE *xappend(args)
- NODE *args;
- {
- NODE *oldstk,arg,list,last,val,*lptr;
-
- /* create a new stack frame */
- oldstk = xlsave(&arg,&list,&last,&val,NULL);
-
- /* initialize */
- arg.n_ptr = args;
-
- /* evaluate and append each argument */
- while (arg.n_ptr) {
-
- /* evaluate the next argument */
- list.n_ptr = xlmatch(LIST,&arg.n_ptr);
-
- /* append each element of this list to the result list */
- while (consp(list.n_ptr)) {
-
- /* append this element */
- lptr = newnode(LIST);
- if (last.n_ptr == NIL)
- val.n_ptr = lptr;
- else
- rplacd(last.n_ptr,lptr);
- rplaca(lptr,car(list.n_ptr));
-
- /* save the new last element */
- last.n_ptr = lptr;
-
- /* move to the next element */
- list.n_ptr = cdr(list.n_ptr);
- }
- }
-
- /* restore previous stack frame */
- xlstack = oldstk;
-
- /* return the list */
- return (val.n_ptr);
- }
-
- /* xreverse - built-in function reverse */
- NODE *xreverse(args)
- NODE *args;
- {
- NODE *oldstk,list,val,*lptr;
-
- /* create a new stack frame */
- oldstk = xlsave(&list,&val,NULL);
-
- /* get the list to reverse */
- list.n_ptr = xlmatch(LIST,&args);
- xllastarg(args);
-
- /* append each element of this list to the result list */
- while (consp(list.n_ptr)) {
-
- /* append this element */
- lptr = newnode(LIST);
- rplaca(lptr,car(list.n_ptr));
- rplacd(lptr,val.n_ptr);
- val.n_ptr = lptr;
-
- /* move to the next element */
- list.n_ptr = cdr(list.n_ptr);
- }
-
- /* restore previous stack frame */
- xlstack = oldstk;
-
- /* return the list */
- return (val.n_ptr);
- }
-
- /* xlast - return the last cons of a list */
- NODE *xlast(args)
- NODE *args;
- {
- NODE *list;
-
- /* get the list */
- list = xlmatch(LIST,&args);
- xllastarg(args);
-
- /* find the last cons */
- while (consp(list) && cdr(list))
- list = cdr(list);
-
- /* return the last element */
- return (list);
- }
-
- /* xmember - built-in function 'member' */
- NODE *xmember(args)
- NODE *args;
- {
- NODE *oldstk,x,list,fcn,*val;
- int tresult;
-
- /* create a new stack frame */
- oldstk = xlsave(&x,&list,&fcn,NULL);
-
- /* get the expression to look for and the list */
- x.n_ptr = xlarg(&args);
- list.n_ptr = xlmatch(LIST,&args);
- xltest(&fcn.n_ptr,&tresult,&args);
- xllastarg(args);
-
- /* look for the expression */
- for (val = NIL; consp(list.n_ptr); list.n_ptr = cdr(list.n_ptr))
- if (dotest(x.n_ptr,car(list.n_ptr),fcn.n_ptr) == tresult) {
- val = list.n_ptr;
- break;
- }
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the result */
- return (val);
- }
-
- /* xassoc - built-in function 'assoc' */
- NODE *xassoc(args)
- NODE *args;
- {
- NODE *oldstk,x,alist,fcn,*pair,*val;
- int tresult;
-
- /* create a new stack frame */
- oldstk = xlsave(&x,&alist,&fcn,NULL);
-
- /* get the expression to look for and the association list */
- x.n_ptr = xlarg(&args);
- alist.n_ptr = xlmatch(LIST,&args);
- xltest(&fcn.n_ptr,&tresult,&args);
- xllastarg(args);
-
- /* look for the expression */
- for (val = NIL; consp(alist.n_ptr); alist.n_ptr = cdr(alist.n_ptr))
- if ((pair = car(alist.n_ptr)) && consp(pair))
- if (dotest(x.n_ptr,car(pair),fcn.n_ptr) == tresult) {
- val = pair;
- break;
- }
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the result */
- return (val);
- }
-
- /* xsubst - substitute one expression for another */
- NODE *xsubst(args)
- NODE *args;
- {
- NODE *oldstk,to,from,expr,fcn,*val;
- int tresult;
-
- /* create a new stack frame */
- oldstk = xlsave(&to,&from,&expr,&fcn,NULL);
-
- /* get the to value, the from value and the expression */
- to.n_ptr = xlarg(&args);
- from.n_ptr = xlarg(&args);
- expr.n_ptr = xlarg(&args);
- xltest(&fcn.n_ptr,&tresult,&args);
- xllastarg(args);
-
- /* do the substitution */
- val = subst(to.n_ptr,from.n_ptr,expr.n_ptr,fcn.n_ptr,tresult);
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the result */
- return (val);
- }
-
- /* subst - substitute one expression for another */
- LOCAL NODE *subst(to,from,expr,fcn,tresult)
- NODE *to,*from,*expr,*fcn; int tresult;
- {
- NODE *oldstk,carval,cdrval,*val;
-
- if (dotest(expr,from,fcn) == tresult)
- val = to;
- else if (consp(expr)) {
- oldstk = xlsave(&carval,&cdrval,NULL);
- carval.n_ptr = subst(to,from,car(expr),fcn,tresult);
- cdrval.n_ptr = subst(to,from,cdr(expr),fcn,tresult);
- val = newnode(LIST);
- rplaca(val,carval.n_ptr);
- rplacd(val,cdrval.n_ptr);
- xlstack = oldstk;
- }
- else
- val = expr;
- return (val);
- }
-
- /* xsublis - substitute using an association list */
- NODE *xsublis(args)
- NODE *args;
- {
- NODE *oldstk,alist,expr,fcn,*val;
- int tresult;
-
- /* create a new stack frame */
- oldstk = xlsave(&alist,&expr,&fcn,NULL);
-
- /* get the assocation list and the expression */
- alist.n_ptr = xlmatch(LIST,&args);
- expr.n_ptr = xlarg(&args);
- xltest(&fcn.n_ptr,&tresult,&args);
- xllastarg(args);
-
- /* do the substitution */
- val = sublis(alist.n_ptr,expr.n_ptr,fcn.n_ptr,tresult);
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the result */
- return (val);
- }
-
- /* sublis - substitute using an association list */
- LOCAL NODE *sublis(alist,expr,fcn,tresult)
- NODE *alist,*expr,*fcn; int tresult;
- {
- NODE *oldstk,carval,cdrval,*val;
-
- if (val = assoc(expr,alist,fcn,tresult))
- val = cdr(val);
- else if (consp(expr)) {
- oldstk = xlsave(&carval,&cdrval,NULL);
- carval.n_ptr = sublis(alist,car(expr),fcn,tresult);
- cdrval.n_ptr = sublis(alist,cdr(expr),fcn,tresult);
- val = newnode(LIST);
- rplaca(val,carval.n_ptr);
- rplacd(val,cdrval.n_ptr);
- xlstack = oldstk;
- }
- else
- val = expr;
- return (val);
- }
-
- /* assoc - find a pair in an association list */
- LOCAL NODE *assoc(expr,alist,fcn,tresult)
- NODE *expr,*alist,*fcn; int tresult;
- {
- NODE *pair;
-
- for (; consp(alist); alist = cdr(alist))
- if ((pair = car(alist)) && consp(pair))
- if (dotest(expr,car(pair),fcn) == tresult)
- return (pair);
- return (NIL);
- }
-
- /* xremove - built-in function 'remove' */
- NODE *xremove(args)
- NODE *args;
- {
- NODE *oldstk,x,list,fcn,val,*p,*last;
- int tresult;
-
- /* create a new stack frame */
- oldstk = xlsave(&x,&list,&fcn,&val,NULL);
-
- /* get the expression to remove and the list */
- x.n_ptr = xlarg(&args);
- list.n_ptr = xlmatch(LIST,&args);
- xltest(&fcn.n_ptr,&tresult,&args);
- xllastarg(args);
-
- /* remove matches */
- while (consp(list.n_ptr)) {
-
- /* check to see if this element should be deleted */
- if (dotest(x.n_ptr,car(list.n_ptr),fcn.n_ptr) != tresult) {
- p = newnode(LIST);
- rplaca(p,car(list.n_ptr));
- if (val.n_ptr) rplacd(last,p);
- else val.n_ptr = p;
- last = p;
- }
-
- /* move to the next element */
- list.n_ptr = cdr(list.n_ptr);
- }
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the updated list */
- return (val.n_ptr);
- }
-
- /* dotest - call a test function */
- int dotest(arg1,arg2,fcn)
- NODE *arg1,*arg2,*fcn;
- {
- NODE *oldstk,args,*val;
-
- /* create a new stack frame */
- oldstk = xlsave(&args,NULL);
-
- /* build an argument list */
- args.n_ptr = newnode(LIST);
- rplaca(args.n_ptr,arg1);
- rplacd(args.n_ptr,newnode(LIST));
- rplaca(cdr(args.n_ptr),arg2);
-
- /* apply the test function */
- val = xlapply(fcn,args.n_ptr);
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the result of the test */
- return (val != NIL);
- }
-
- /* xnth - return the nth element of a list */
- NODE *xnth(args)
- NODE *args;
- {
- return (nth(args,FALSE));
- }
-
- /* xnthcdr - return the nth cdr of a list */
- NODE *xnthcdr(args)
- NODE *args;
- {
- return (nth(args,TRUE));
- }
-
- /* nth - internal nth function */
- LOCAL NODE *nth(args,cdrflag)
- NODE *args; int cdrflag;
- {
- NODE *list;
- int n;
-
- /* get n and the list */
- if ((n = xlmatch(INT,&args)->n_int) < 0)
- xlfail("bad argument");
- if ((list = xlmatch(LIST,&args)) == NIL)
- xlfail("bad argument");
- xllastarg(args);
-
- /* find the nth element */
- for (; n > 0 && consp(list); n--)
- list = cdr(list);
-
- /* return the list beginning at the nth element */
- return (cdrflag || !consp(list) ? list : car(list));
- }
-
- /* xlength - return the length of a list */
- NODE *xlength(args)
- NODE *args;
- {
- NODE *list,*val;
- int n;
-
- /* get the list */
- list = xlmatch(LIST,&args);
- xllastarg(args);
-
- /* find the length */
- for (n = 0; consp(list); n++)
- list = cdr(list);
-
- /* create the value node */
- val = newnode(INT);
- val->n_int = n;
-
- /* return the length */
- return (val);
- }
-
- /* xmapc - built-in function 'mapc' */
- NODE *xmapc(args)
- NODE *args;
- {
- return (map(args,TRUE,FALSE));
- }
-
- /* xmapcar - built-in function 'mapcar' */
- NODE *xmapcar(args)
- NODE *args;
- {
- return (map(args,TRUE,TRUE));
- }
-
- /* xmapl - built-in function 'mapl' */
- NODE *xmapl(args)
- NODE *args;
- {
- return (map(args,FALSE,FALSE));
- }
-
- /* xmaplist - built-in function 'maplist' */
- NODE *xmaplist(args)
- NODE *args;
- {
- return (map(args,FALSE,TRUE));
- }
-
- /* map - internal mapping function */
- LOCAL NODE *map(args,carflag,valflag)
- NODE *args; int carflag,valflag;
- {
- NODE *oldstk,fcn,lists,arglist,val,*last,*p,*x,*y;
-
- /* create a new stack frame */
- oldstk = xlsave(&fcn,&lists,&arglist,&val,NULL);
-
- /* get the function to apply and the first list */
- fcn.n_ptr = xlarg(&args);
- lists.n_ptr = xlmatch(LIST,&args);
-
- /* save the first list if not saving function values */
- if (!valflag)
- val.n_ptr = lists.n_ptr;
-
- /* set up the list of argument lists */
- p = newnode(LIST);
- rplaca(p,lists.n_ptr);
- lists.n_ptr = p;
-
- /* get the remaining argument lists */
- while (args) {
- p = newnode(LIST);
- rplacd(p,lists.n_ptr);
- lists.n_ptr = p;
- rplaca(p,xlmatch(LIST,&args));
- }
-
- /* if the function is a symbol, get its value */
- if (symbolp(fcn.n_ptr))
- fcn.n_ptr = xleval(fcn.n_ptr);
-
- /* loop through each of the argument lists */
- for (;;) {
-
- /* build an argument list from the sublists */
- arglist.n_ptr = NIL;
- for (x = lists.n_ptr; x && (y = car(x)) && consp(y); x = cdr(x)) {
- p = newnode(LIST);
- rplacd(p,arglist.n_ptr);
- arglist.n_ptr = p;
- rplaca(p,carflag ? car(y) : y);
- rplaca(x,cdr(y));
- }
-
- /* quit if any of the lists were empty */
- if (x) break;
-
- /* apply the function to the arguments */
- if (valflag) {
- p = newnode(LIST);
- if (val.n_ptr) rplacd(last,p);
- else val.n_ptr = p;
- rplaca(p,xlapply(fcn.n_ptr,arglist.n_ptr));
- last = p;
- }
- else
- xlapply(fcn.n_ptr,arglist.n_ptr);
- }
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the last test expression value */
- return (val.n_ptr);
- }
-
- /* xrplca - replace the car of a list node */
- NODE *xrplca(args)
- NODE *args;
- {
- NODE *list,*newcar;
-
- /* get the list and the new car */
- if ((list = xlmatch(LIST,&args)) == NIL)
- xlfail("bad argument");
- newcar = xlarg(&args);
- xllastarg(args);
-
- /* replace the car */
- rplaca(list,newcar);
-
- /* return the list node that was modified */
- return (list);
- }
-
- /* xrplcd - replace the cdr of a list node */
- NODE *xrplcd(args)
- NODE *args;
- {
- NODE *list,*newcdr;
-
- /* get the list and the new cdr */
- if ((list = xlmatch(LIST,&args)) == NIL)
- xlfail("bad argument");
- newcdr = xlarg(&args);
- xllastarg(args);
-
- /* replace the cdr */
- rplacd(list,newcdr);
-
- /* return the list node that was modified */
- return (list);
- }
-
- /* xnconc - destructively append lists */
- NODE *xnconc(args)
- NODE *args;
- {
- NODE *list,*last,*val;
-
- /* concatenate each argument */
- for (val = NIL; args; ) {
-
- /* concatenate this list */
- if (list = xlmatch(LIST,&args)) {
-
- /* check for this being the first non-empty list */
- if (val)
- rplacd(last,list);
- else
- val = list;
-
- /* find the end of the list */
- while (consp(cdr(list)))
- list = cdr(list);
-
- /* save the new last element */
- last = list;
- }
- }
-
- /* return the list */
- return (val);
- }
-
- /* xdelete - built-in function 'delete' */
- NODE *xdelete(args)
- NODE *args;
- {
- NODE *oldstk,x,list,fcn,*last,*val;
- int tresult;
-
- /* create a new stack frame */
- oldstk = xlsave(&x,&list,&fcn,NULL);
-
- /* get the expression to delete and the list */
- x.n_ptr = xlarg(&args);
- list.n_ptr = xlmatch(LIST,&args);
- xltest(&fcn.n_ptr,&tresult,&args);
- xllastarg(args);
-
- /* delete leading matches */
- while (consp(list.n_ptr)) {
- if (dotest(x.n_ptr,car(list.n_ptr),fcn.n_ptr) != tresult)
- break;
- list.n_ptr = cdr(list.n_ptr);
- }
- val = last = list.n_ptr;
-
- /* delete embedded matches */
- if (consp(list.n_ptr)) {
-
- /* skip the first non-matching element */
- list.n_ptr = cdr(list.n_ptr);
-
- /* look for embedded matches */
- while (consp(list.n_ptr)) {
-
- /* check to see if this element should be deleted */
- if (dotest(x.n_ptr,car(list.n_ptr),fcn.n_ptr) == tresult)
- rplacd(last,cdr(list.n_ptr));
- else
- last = list.n_ptr;
-
- /* move to the next element */
- list.n_ptr = cdr(list.n_ptr);
- }
- }
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the updated list */
- return (val);
- }
-
- /* xatom - is this an atom? */
- NODE *xatom(args)
- NODE *args;
- {
- NODE *arg;
- arg = xlarg(&args);
- xllastarg(args);
- return (atom(arg) ? true : NIL);
- }
-
- /* xsymbolp - is this an symbol? */
- NODE *xsymbolp(args)
- NODE *args;
- {
- NODE *arg;
- arg = xlarg(&args);
- xllastarg(args);
- return (arg == NIL || symbolp(arg) ? true : NIL);
- }
-
- /* xnumberp - is this an number? */
- NODE *xnumberp(args)
- NODE *args;
- {
- NODE *arg;
- arg = xlarg(&args);
- xllastarg(args);
- return (fixp(arg) ? true : NIL);
- }
-
- /* xboundp - is this a value bound to this symbol? */
- NODE *xboundp(args)
- NODE *args;
- {
- NODE *sym;
- sym = xlmatch(SYM,&args);
- xllastarg(args);
- return (sym->n_symvalue == s_unbound ? NIL : true);
- }
-
- /* xnull - is this null? */
- NODE *xnull(args)
- NODE *args;
- {
- NODE *arg;
- arg = xlarg(&args);
- xllastarg(args);
- return (null(arg) ? true : NIL);
- }
-
- /* xlistp - is this a list? */
- NODE *xlistp(args)
- NODE *args;
- {
- NODE *arg;
- arg = xlarg(&args);
- xllastarg(args);
- return (listp(arg) ? true : NIL);
- }
-
- /* xconsp - is this a cons? */
- NODE *xconsp(args)
- NODE *args;
- {
- NODE *arg;
- arg = xlarg(&args);
- xllastarg(args);
- return (consp(arg) ? true : NIL);
- }
-
- /* xeq - are these equal? */
- NODE *xeq(args)
- NODE *args;
- {
- return (cequal(args,eq));
- }
-
- /* xeql - are these equal? */
- NODE *xeql(args)
- NODE *args;
- {
- return (cequal(args,eql));
- }
-
- /* xequal - are these equal? */
- NODE *xequal(args)
- NODE *args;
- {
- return (cequal(args,equal));
- }
-
- /* cequal - common eq/eql/equal function */
- LOCAL NODE *cequal(args,fcn)
- NODE *args; int (*fcn)();
- {
- NODE *arg1,*arg2;
-
- /* get the two arguments */
- arg1 = xlarg(&args);
- arg2 = xlarg(&args);
- xllastarg(args);
-
- /* compare the arguments */
- return ((*fcn)(arg1,arg2) ? true : NIL);
- }
- SHAR_EOF
- if test 17752 -ne "`wc -c < 'xllist.c'`"
- then
- echo shar: error transmitting "'xllist.c'" '(should have been 17752 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'xlobj.c'" '(16101 characters)'
- if test -f 'xlobj.c'
- then
- echo shar: will not over-write existing file "'xlobj.c'"
- else
- sed 's/^X//' << \SHAR_EOF > 'xlobj.c'
- /* xlobj - xlisp object functions */
-
- #include "xlisp.h"
-
- #ifdef MEGAMAX
- overlay "overflow"
- #endif
-
- /* external variables */
- extern NODE *xlstack;
- extern NODE *xlenv,*xlnewenv;
- extern NODE *s_stdout;
- extern NODE *self;
- extern NODE *class;
- extern NODE *object;
- extern NODE *new;
- extern NODE *isnew;
- extern NODE *msgcls;
- extern NODE *msgclass;
- extern int varcnt;
-
- /* instance variable numbers for the class 'Class' */
- #define MESSAGES 0 /* list of messages */
- #define IVARS 1 /* list of instance variable names */
- #define CVARS 2 /* list of class variable names */
- #define CVALS 3 /* list of class variable values */
- #define SUPERCLASS 4 /* pointer to the superclass */
- #define IVARCNT 5 /* number of class instance variables */
- #define IVARTOTAL 6 /* total number of instance variables */
-
- /* number of instance variables for the class 'Class' */
- #define CLASSSIZE 7
-
- /* forward declarations */
- XFORWARD NODE *xlgetivar();
- XFORWARD NODE *xlsetivar();
- XFORWARD NODE *xlivar();
- XFORWARD NODE *xlcvar();
- XFORWARD NODE *findmsg();
- XFORWARD NODE *findvar();
- XFORWARD NODE *defvars();
- XFORWARD NODE *makelist();
-
- /* xlclass - define a class */
- NODE *xlclass(name,vcnt)
- char *name; int vcnt;
- {
- NODE *sym,*cls;
-
- /* create the class */
- sym = xlsenter(name);
- cls = sym->n_symvalue = newnode(OBJ);
- cls->n_obclass = class;
- cls->n_obdata = makelist(CLASSSIZE);
-
- /* set the instance variable counts */
- if (vcnt > 0) {
- xlsetivar(cls,IVARCNT,newnode(INT))->n_int = vcnt;
- xlsetivar(cls,IVARTOTAL,newnode(INT))->n_int = vcnt;
- }
-
- /* set the superclass to 'Object' */
- xlsetivar(cls,SUPERCLASS,object);
-
- /* return the new class */
- return (cls);
- }
-
- /* xlmfind - find the message binding for a message to an object */
- NODE *xlmfind(obj,msym)
- NODE *obj,*msym;
- {
- return (findmsg(obj->n_obclass,msym));
- }
-
- /* xlxsend - send a message to an object */
- NODE *xlxsend(obj,msg,args)
- NODE *obj,*msg,*args;
- {
- NODE *oldstk,*oldenv,*oldnewenv,method,cptr,eargs,val,*isnewmsg;
-
- /* save the old environment */
- oldnewenv = xlnewenv; oldenv = xlnewenv = xlenv;
-
- /* create a new stack frame */
- oldstk = xlsave(&method,&cptr,&eargs,&val,NULL);
-
- /* get the method for this message */
- method.n_ptr = cdr(msg);
-
- /* make sure its a function or a subr */
- if (!subrp(method.n_ptr) && !consp(method.n_ptr))
- xlfail("bad method");
-
- /* bind the symbols 'self' and 'msgclass' */
- xlbind(self,obj);
- xlbind(msgclass,msgcls);
-
- /* evaluate the function call */
- eargs.n_ptr = xlevlist(args);
- if (subrp(method.n_ptr)) {
- xlfixbindings();
- val.n_ptr = (*method.n_ptr->n_subr)(eargs.n_ptr);
- }
- else {
-
- /* bind the formal arguments */
- xlabind(car(method.n_ptr),eargs.n_ptr);
- xlfixbindings();
-
- /* execute the code */
- cptr.n_ptr = cdr(method.n_ptr);
- while (cptr.n_ptr != NIL)
- val.n_ptr = xlevarg(&cptr.n_ptr);
- }
-
- /* restore the environment */
- xlunbind(oldenv); xlnewenv = oldnewenv;
-
- /* after creating an object, send it the "isnew" message */
- if (car(msg) == new && val.n_ptr != NIL) {
- if ((isnewmsg = xlmfind(val.n_ptr,isnew)) == NIL)
- xlfail("no method for the isnew message");
- val.n_ptr = xlxsend(val.n_ptr,isnewmsg,args);
- }
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the result value */
- return (val.n_ptr);
- }
-
- /* xlsend - send a message to an object (message in arg list) */
- NODE *xlsend(obj,args)
- NODE *obj,*args;
- {
- NODE *msg;
-
- /* find the message binding for this message */
- if ((msg = xlmfind(obj,xlevmatch(SYM,&args))) == NIL)
- xlfail("no method for this message");
-
- /* send the message */
- return (xlxsend(obj,msg,args));
- }
-
- /* xlobsym - find a class or instance variable for the current object */
- NODE *xlobsym(sym)
- NODE *sym;
- {
- NODE *obj;
-
- if ((obj = self->n_symvalue) != NIL && objectp(obj))
- return (findvar(obj,sym));
- else
- return (NIL);
- }
-
- /* mnew - create a new object instance */
- LOCAL NODE *mnew()
- {
- NODE *oldstk,obj,*cls;
-
- /* create a new stack frame */
- oldstk = xlsave(&obj,NULL);
-
- /* get the class */
- cls = self->n_symvalue;
-
- /* generate a new object */
- obj.n_ptr = newnode(OBJ);
- obj.n_ptr->n_obclass = cls;
- obj.n_ptr->n_obdata = makelist(getivcnt(cls,IVARTOTAL));
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the new object */
- return (obj.n_ptr);
- }
-
- /* misnew - initialize a new class */
- LOCAL NODE *misnew(args)
- NODE *args;
- {
- NODE *oldstk,super,*obj;
-
- /* create a new stack frame */
- oldstk = xlsave(&super,NULL);
-
- /* get the superclass if there is one */
- if (args != NIL)
- super.n_ptr = xlmatch(OBJ,&args);
- else
- super.n_ptr = object;
- xllastarg(args);
-
- /* get the object */
- obj = self->n_symvalue;
-
- /* store the superclass */
- xlsetivar(obj,SUPERCLASS,super.n_ptr);
- xlsetivar(obj,IVARTOTAL,newnode(INT))->n_int =
- getivcnt(super.n_ptr,IVARTOTAL);
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the new object */
- return (obj);
- }
-
- /* xladdivar - enter an instance variable */
- xladdivar(cls,var)
- NODE *cls; char *var;
- {
- NODE *ivar,*lptr;
-
- /* find the 'ivars' instance variable */
- ivar = xlivar(cls,IVARS);
-
- /* add the instance variable */
- lptr = newnode(LIST);
- rplacd(lptr,car(ivar));
- rplaca(ivar,lptr);
- rplaca(lptr,xlsenter(var));
- }
-
- /* entermsg - add a message to a class */
- LOCAL NODE *entermsg(cls,msg)
- NODE *cls,*msg;
- {
- NODE *ivar,*lptr,*mptr;
-
- /* find the 'messages' instance variable */
- ivar = xlivar(cls,MESSAGES);
-
- /* lookup the message */
- for (lptr = car(ivar); lptr != NIL; lptr = cdr(lptr))
- if (car(mptr = car(lptr)) == msg)
- return (mptr);
-
- /* allocate a new message entry if one wasn't found */
- lptr = newnode(LIST);
- rplacd(lptr,car(ivar));
- rplaca(ivar,lptr);
- rplaca(lptr,mptr = newnode(LIST));
- rplaca(mptr,msg);
-
- /* return the symbol node */
- return (mptr);
- }
-
- /* answer - define a method for answering a message */
- LOCAL NODE *answer(args)
- NODE *args;
- {
- NODE *oldstk,arg,msg,fargs,code;
- NODE *obj,*mptr,*fptr;
-
- /* create a new stack frame */
- oldstk = xlsave(&arg,&msg,&fargs,&code,NULL);
-
- /* initialize */
- arg.n_ptr = args;
-
- /* message symbol, formal argument list and code */
- msg.n_ptr = xlmatch(SYM,&arg.n_ptr);
- fargs.n_ptr = xlmatch(LIST,&arg.n_ptr);
- code.n_ptr = xlmatch(LIST,&arg.n_ptr);
- xllastarg(arg.n_ptr);
-
- /* get the object node */
- obj = self->n_symvalue;
-
- /* make a new message list entry */
- mptr = entermsg(obj,msg.n_ptr);
-
- /* setup the message node */
- rplacd(mptr,fptr = newnode(LIST));
- rplaca(fptr,fargs.n_ptr);
- rplacd(fptr,code.n_ptr);
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the object */
- return (obj);
- }
-
- /* mivars - define the list of instance variables */
- LOCAL NODE *mivars(args)
- NODE *args;
- {
- NODE *cls,*super;
- int scnt;
-
- /* define the list of instance variables */
- cls = defvars(args,IVARS);
-
- /* get the superclass instance variable count */
- if ((super = xlgetivar(cls,SUPERCLASS)) != NIL)
- scnt = getivcnt(super,IVARTOTAL);
- else
- scnt = 0;
-
- /* save the number of instance variables */
- xlsetivar(cls,IVARCNT,newnode(INT))->n_int = varcnt;
- xlsetivar(cls,IVARTOTAL,newnode(INT))->n_int = scnt+varcnt;
-
- /* return the class */
- return (cls);
- }
-
- /* getivcnt - get the number of instance variables for a class */
- LOCAL int getivcnt(cls,ivar)
- NODE *cls; int ivar;
- {
- NODE *cnt;
-
- if ((cnt = xlgetivar(cls,ivar)) != NIL)
- if (fixp(cnt))
- return (cnt->n_int);
- else
- xlfail("bad value for instance variable count");
- else
- return (0);
- }
-
- /* mcvars - define the list of class variables */
- LOCAL NODE *mcvars(args)
- NODE *args;
- {
- NODE *cls;
-
- /* define the list of class variables */
- cls = defvars(args,CVARS);
-
- /* make a new list of values */
- xlsetivar(cls,CVALS,makelist(varcnt));
-
- /* return the class */
- return (cls);
- }
-
- /* defvars - define a class or instance variable list */
- LOCAL NODE *defvars(args,varnum)
- NODE *args; int varnum;
- {
- NODE *oldstk,vars,*vptr,*cls,*sym;
-
- /* create a new stack frame */
- oldstk = xlsave(&vars,NULL);
-
- /* get ivar list */
- vars.n_ptr = xlmatch(LIST,&args);
- xllastarg(args);
-
- /* get the class node */
- cls = self->n_symvalue;
-
- /* check each variable in the list */
- varcnt = 0;
- for (vptr = vars.n_ptr;
- consp(vptr);
- vptr = cdr(vptr)) {
-
- /* make sure this is a valid symbol in the list */
- if ((sym = car(vptr)) == NIL || !symbolp(sym))
- xlfail("bad variable list");
-
- /* make sure its not already defined */
- if (checkvar(cls,sym))
- xlfail("multiply defined variable");
-
- /* count the variable */
- varcnt++;
- }
-
- /* make sure the list ended properly */
- if (vptr != NIL)
- xlfail("bad variable list");
-
- /* define the new variable list */
- xlsetivar(cls,varnum,vars.n_ptr);
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the class */
- return (cls);
- }
-
- /* xladdmsg - add a message to a class */
- xladdmsg(cls,msg,code)
- NODE *cls; char *msg; NODE *(*code)();
- {
- NODE *mptr;
-
- /* enter the message selector */
- mptr = entermsg(cls,xlsenter(msg));
-
- /* store the method for this message */
- rplacd(mptr,newnode(SUBR));
- cdr(mptr)->n_subr = code;
- }
-
- /* getclass - get the class of an object */
- LOCAL NODE *getclass(args)
- NODE *args;
- {
- /* make sure there aren't any arguments */
- xllastarg(args);
-
- /* return the object's class */
- return (self->n_symvalue->n_obclass);
- }
-
- /* obshow - show the instance variables of an object */
- LOCAL NODE *obshow(args)
- NODE *args;
- {
- NODE *fptr;
-
- /* get the file pointer */
- fptr = (args ? xlmatch(FPTR,&args) : s_stdout->n_symvalue);
- xllastarg(args);
-
- /* print the object's instance variables */
- xlprint(fptr,self->n_symvalue->n_obdata,TRUE);
- xlterpri(fptr);
-
- /* return the object */
- return (self->n_symvalue);
- }
-
- /* defisnew - default 'isnew' method */
- LOCAL NODE *defisnew(args)
- NODE *args;
- {
- /* make sure there aren't any arguments */
- xllastarg(args);
-
- /* return the object */
- return (self->n_symvalue);
- }
-
- /* sendsuper - send a message to an object's superclass */
- LOCAL NODE *sendsuper(args)
- NODE *args;
- {
- NODE *obj,*super,*msg;
-
- /* get the object */
- obj = self->n_symvalue;
-
- /* get the object's superclass */
- super = xlgetivar(obj->n_obclass,SUPERCLASS);
-
- /* find the message binding for this message */
- if ((msg = findmsg(super,xlmatch(SYM,&args))) == NIL)
- xlfail("no method for this message");
-
- /* send the message */
- return (xlxsend(obj,msg,args));
- }
-
- /* findmsg - find the message binding given an object and a class */
- LOCAL NODE *findmsg(cls,sym)
- NODE *cls,*sym;
- {
- NODE *lptr,*msg;
-
- /* start at the specified class */
- msgcls = cls;
-
- /* look for the message in the class or superclasses */
- while (msgcls != NIL) {
-
- /* lookup the message in this class */
- for (lptr = xlgetivar(msgcls,MESSAGES);
- lptr != NIL;
- lptr = cdr(lptr))
- if ((msg = car(lptr)) != NIL && car(msg) == sym)
- return (msg);
-
- /* look in class's superclass */
- msgcls = xlgetivar(msgcls,SUPERCLASS);
- }
-
- /* message not found */
- return (NIL);
- }
-
- /* findvar - find a class or instance variable */
- LOCAL NODE *findvar(obj,sym)
- NODE *obj,*sym;
- {
- NODE *cls,*lptr;
- int base,varnum;
- int found;
-
- /* get the class of the object */
- cls = obj->n_obclass;
-
- /* get the total number of instance variables */
- base = getivcnt(cls,IVARTOTAL);
-
- /* find the variable */
- found = FALSE;
- for (; cls != NIL; cls = xlgetivar(cls,SUPERCLASS)) {
-
- /* get the number of instance variables for this class */
- if ((base -= getivcnt(cls,IVARCNT)) < 0)
- xlfail("error finding instance variable");
-
- /* check for finding the class of the current message */
- if (!found && cls == msgclass->n_symvalue)
- found = TRUE;
-
- /* lookup the instance variable */
- varnum = 0;
- for (lptr = xlgetivar(cls,IVARS);
- lptr != NIL;
- lptr = cdr(lptr))
- if (found && car(lptr) == sym)
- return (xlivar(obj,base + varnum));
- else
- varnum++;
-
- /* skip the class variables if the message class hasn't been found */
- if (!found)
- continue;
-
- /* lookup the class variable */
- varnum = 0;
- for (lptr = xlgetivar(cls,CVARS);
- lptr != NIL;
- lptr = cdr(lptr))
- if (car(lptr) == sym)
- return (xlcvar(cls,varnum));
- else
- varnum++;
- }
-
- /* variable not found */
- return (NIL);
- }
-
- /* checkvar - check for an existing class or instance variable */
- LOCAL int checkvar(cls,sym)
- NODE *cls,*sym;
- {
- NODE *lptr;
-
- /* find the variable */
- for (; cls != NIL; cls = xlgetivar(cls,SUPERCLASS)) {
-
- /* lookup the instance variable */
- for (lptr = xlgetivar(cls,IVARS);
- lptr != NIL;
- lptr = cdr(lptr))
- if (car(lptr) == sym)
- return (TRUE);
-
- /* lookup the class variable */
- for (lptr = xlgetivar(cls,CVARS);
- lptr != NIL;
- lptr = cdr(lptr))
- if (car(lptr) == sym)
- return (TRUE);
- }
-
- /* variable not found */
- return (FALSE);
- }
-
- /* xlgetivar - get the value of an instance variable */
- NODE *xlgetivar(obj,num)
- NODE *obj; int num;
- {
- return (car(xlivar(obj,num)));
- }
-
- /* xlsetivar - set the value of an instance variable */
- NODE *xlsetivar(obj,num,val)
- NODE *obj; int num; NODE *val;
- {
- rplaca(xlivar(obj,num),val);
- return (val);
- }
-
- /* xlivar - get an instance variable */
- NODE *xlivar(obj,num)
- NODE *obj; int num;
- {
- NODE *ivar;
-
- /* get the instance variable */
- for (ivar = obj->n_obdata; num > 0; num--)
- if (ivar != NIL)
- ivar = cdr(ivar);
- else
- xlfail("bad instance variable list");
-
- /* return the instance variable */
- return (ivar);
- }
-
- /* xlcvar - get a class variable */
- NODE *xlcvar(cls,num)
- NODE *cls; int num;
- {
- NODE *cvar;
-
- /* get the class variable */
- for (cvar = xlgetivar(cls,CVALS); num > 0; num--)
- if (cvar != NIL)
- cvar = cdr(cvar);
- else
- xlfail("bad class variable list");
-
- /* return the class variable */
- return (cvar);
- }
-
- /* makelist - make a list of nodes */
- LOCAL NODE *makelist(cnt)
- int cnt;
- {
- NODE *oldstk,list,*lnew;
-
- /* create a new stack frame */
- oldstk = xlsave(&list,NULL);
-
- /* make the list */
- for (; cnt > 0; cnt--) {
- lnew = newnode(LIST);
- rplacd(lnew,list.n_ptr);
- list.n_ptr = lnew;
- }
-
- /* restore the previous stack frame */
- xlstack = oldstk;
-
- /* return the list */
- return (list.n_ptr);
- }
-
- /* xloinit - object function initialization routine */
- xloinit()
- {
- /* don't confuse the garbage collector */
- class = object = NIL;
-
- /* enter the object related symbols */
- new = xlsenter("new");
- isnew = xlsenter("isnew");
- self = xlsenter("self");
- msgclass = xlsenter("msgclass");
-
- /* create the 'Class' object */
- class = xlclass("Class",CLASSSIZE);
- class->n_obclass = class;
-
- /* create the 'Object' object */
- object = xlclass("Object",0);
-
- /* finish initializing 'class' */
- xlsetivar(class,SUPERCLASS,object);
- xladdivar(class,"ivartotal"); /* ivar number 6 */
- xladdivar(class,"ivarcnt"); /* ivar number 5 */
- xladdivar(class,"superclass"); /* ivar number 4 */
- xladdivar(class,"cvals"); /* ivar number 3 */
- xladdivar(class,"cvars"); /* ivar number 2 */
- xladdivar(class,"ivars"); /* ivar number 1 */
- xladdivar(class,"messages"); /* ivar number 0 */
- xladdmsg(class,"new",mnew);
- xladdmsg(class,"answer",answer);
- xladdmsg(class,"ivars",mivars);
- xladdmsg(class,"cvars",mcvars);
- xladdmsg(class,"isnew",misnew);
-
- /* finish initializing 'object' */
- xladdmsg(object,"class",getclass);
- xladdmsg(object,"show",obshow);
- xladdmsg(object,"isnew",defisnew);
- xladdmsg(object,"sendsuper",sendsuper);
- }
- SHAR_EOF
- if test 16101 -ne "`wc -c < 'xlobj.c'`"
- then
- echo shar: error transmitting "'xlobj.c'" '(should have been 16101 characters)'
- fi
- fi # end of overwriting check
- # End of shell archive
- exit 0
-
-